<%@page import="com.blog.dto.Article"%>
<%@page import="com.blog.dao.ArticleDao"%>
<%@page import="com.blog.dto.Tag"%>
<%@page import="com.blog.dao.TagDao"%>
<%@page import="com.blog.dto.Category"%>
<%@page import="java.util.Vector"%>
<%@page import="com.blog.dao.CategoryDao"%>
<%@page import="com.blog.dto.User"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath+"admin/"%>">
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="Bookmark" href="/favicon.ico" >
<link rel="Shortcut Icon" href="/favicon.ico" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<!--/meta 作为公共模版分离出去-->

<title>新增文章 - 资讯管理</title>
<meta name="keywords" content="H-ui.admin v3.1,H-ui网站后台模版,后台模版下载,后台管理系统模版,HTML后台模版下载">
<meta name="description" content="H-ui.admin v3.1，是一款由国人开发的轻量级扁平化网站后台模板，完全免费开源的网站后台管理系统模版，适合中小型CMS后台系统。">
</head>
<body>
<article class="page-container">
				<%
					User user = new User();
					user=(User)session.getAttribute("user");
					ArticleDao articleDao = new ArticleDao();
					Article art = new Article();
					int article_id=Integer.parseInt(request.getParameter("article_id"));
					art = (articleDao.findArticleById(article_id)).get(0);
				%>
	<form class="form form-horizontal" id="form-article-edit">
		<input type="hidden" class="input-text" value="<%=article_id %>" placeholder="" id="article_id" name="article_id">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>文章标题：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="<%=art.getTitle() %>" placeholder="" id="title" name="title">
			</div>
		</div>
		
		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>文章类型：</label>
			<div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
			
				<select name="category" class="select">
				<%
					CategoryDao categoryDao = new CategoryDao();
					Vector<Category> vCate = categoryDao.findAllCategory();
					for(Category cate : vCate){
				%>
					<option value="<%=cate.getCategory() %>" ><%=cate.getCategory() %></option>
				<%	} %>
					<!-- <option value="培训">培训</option>
					<option value="竞赛">竞赛</option> -->
				</select>
				</span> </div>
		</div>
		<div class="row cl">
		
			<p>
				<label class="form-label col-xs-4 col-sm-2">标签：</label>
				<input type="text" id="addTag">
				<a href="javascript:;" id="addBtn" onclick="appendTag()" class="btn btn-primary radius"><i class="Hui-iconfont"></i> 添加标签</a>
				<!-- <input type="botton" id="addBtn" onclick="appendTag()" placeholder="添加标签"  > -->
			</p>
			<div id="tagCheckbox" class="row cl" style="padding-right:150px;">
			<label class="form-label col-xs-4 col-sm-2"  >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
				<%
					String tags = art.getTag();
					String[] tagArrays = tags.split(","); 
					TagDao tagDao = new TagDao();
					Vector<Tag> vTags = new Vector<Tag>();
					vTags = tagDao.findTagByUser_id(user.getUser_id());
					boolean tagFlag = false;
					for( Tag tag : vTags ){
						tagFlag = false;
						for(String tt : tagArrays){
							if(tt.equals(tag.getTag_name())){
								tagFlag = true ;
								break;
							}
						}
						if(tagFlag){
				%>
							<span class="label label-success radius" onclick="tag_nochecked(this,'<%=tag.getTag_name() %>')"   ><input type="checkbox" name="tag" checked="checked" value="<%=tag.getTag_name() %>"><%=tag.getTag_name() %></span>
				<%
							
						}else{
				%>
							<span class="label label-default radius" onclick="tag_checked(this,'<%=tag.getTag_name() %>')" ><input type="checkbox" name="tag"  value="<%=tag.getTag_name() %>"><%=tag.getTag_name() %></span>
				<%	
						}
					}	
				%>
				<!-- <input type="checkbox" id="tag" name="tag" value=""> -->
			</div>
			
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">关键词：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="<%=art.getKeyword() %>" placeholder="" id="keyword" name="keyword">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">文章摘要：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<textarea name="description" cols="" rows="" class="textarea"  placeholder="说点什么...最少输入10个字符" datatype="*10-100" dragonfly="true" nullmsg="备注不能为空！" onKeyUp="$.Huitextarealength(this,200)"><%=art.getDescription() %></textarea>
				<p class="textarea-numberbar"><em class="textarea-length">0</em>/200</p>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">文章作者：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="hidden" class="input-text" value="<%=user.getUser_id() %>" readonly="readonly" placeholder="" id="user_id" name="user_id">
				<input type="text" class="input-text" value="<%=user.getUsername() %>" readonly="readonly" placeholder="" id="author" name="author">
			</div>
		</div>
		<!-- <div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">文章来源：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="0" placeholder="" id="sources" name="sources">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">允许评论：</label>
			<div class="formControls col-xs-8 col-sm-9 skin-minimal">
				<div class="check-box">
					<input type="checkbox" id="allowcomments" name="allowcomments" value="">
					<label for="checkbox-pinglun">&nbsp;</label>
				</div>
			</div>
		</div> -->
		<div class="row cl">
		
			<label class="form-label col-xs-4 col-sm-2">缩略图：</label>
			
			<div id="upload-cover" style="width: 45px; height: 30px; float: left; margin-left: 14px; border: 1px solid #808080">
				<img id="cover-img" src="<%=art.getImage() %>" width="45" height="30" style="position: absolute" />
			</div>
			<input type="hidden"  value="<%=art.getImage() %>"  id="cover" name="cover">
		</div>
		
		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">文章内容：</label>
			<div class="formControls col-xs-8 col-sm-9"> 
				<script id="editor" type="text/plain" style="width:100%;height:400px;"><%=art.getContent() %></script> 
			</div>
		</div>
		
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
				<button  class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 提交</button>
				<!-- <button onClick="article_save();" class="btn btn-secondary radius" type="button"><i class="Hui-iconfont">&#xe632;</i> 保存草稿</button> -->
				<button onClick="removeIframe();" class="btn btn-default radius" type="button">&nbsp;&nbsp;关闭&nbsp;&nbsp;</button>
			</div>
		</div>
	</form>
</article>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer /作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="lib/webuploader/0.1.5/webuploader.min.js"></script> 
<script type="text/javascript" src="lib/ueditor/1.4.3/ueditor.config.js"></script> 
<script type="text/javascript" src="lib/ueditor/1.4.3/ueditor.all.js"> </script> 
<script type="text/javascript" src="lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
/*选择-停用*/
function tag_nochecked(obj,tagContent){
	
	$(obj).after('<span class="label label-default radius" onclick="tag_checked(this,\''+tagContent+'\')"  ><input type="checkbox"  id="tag" name="tag" value="'+tagContent+'">'+tagContent+'</span>' );
	$(obj).remove();
}

/*选择-启用*/
function tag_checked(obj,tagContent){
	$(obj).after('<span class="label label-success radius" onclick="tag_nochecked(this,\''+tagContent+'\')" ><input type="checkbox" checked="checked" id="tag" name="tag" value="'+tagContent+'">'+tagContent+'</span>' );
	$(obj).remove();
}

function appendTag(){

	//获取已有的标签
    var tagContent = $("#addTag").val();
    if(tagContent==''){
        alert("输入不能为空！");
        return false;
    }
    //比较已有标签
	var InputObj= $("#tagCheckbox").children();
	for( i = 0 ; i<InputObj.length ; i++){
	    if($(InputObj[i]).val()== tagContent ){
            alert("不能输入相同的标签！请重新输入！");
            return false;
		}
	}
	var tagCheckbox='<span class="label label-success radius" onclick="tag_nochecked(this,\''+tagContent+'\')" ><input type="checkbox" checked="checked" id="tag" name="tag" value="'+tagContent+'">'+tagContent+'</span>';              // 使用 HTML 标签创建文本
	$("#tagCheckbox").append(tagCheckbox);        // 追加新元素
	return false;
}

function removeIframe(){
	var index = parent.layer.getFrameIndex(window.name);
	parent.$('.btn-refresh').click();
	parent.layer.close(index); 
}


$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	//表单验证
	$("#form-article-edit").validate({
		rules:{
			title:{
				required:true,
			},
			articlecolumn:{
				required:true,
			},
			category:{
				required:true,
			},
			articlesort:{
				required:true,
			},
			keywords:{
				required:true,
			},
			description:{
				required:true,
			},
			author:{
				required:true,
			},
			sources:{
				required:true,
			},
			allowcomments:{
				required:true,
			},
			commentdatemin:{
				required:true,
			},
			commentdatemax:{
				required:true,
			},

		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit({
				type: 'POST',
				url: '<%=request.getContextPath()+"/articleServlet?act=edit" %>',
				success: function(data){
					layer.msg('修改成功!',{icon:1,time:1000});
				},
                error: function(XmlHttpRequest, textStatus, errorThrown){
					layer.msg('error!',{icon:2,time:1000});
				}
			});
			var index = parent.layer.getFrameIndex(window.name);
			parent.$('.btn-refresh').click();
			//parent.layer.close(index); 
		}
	});
	
	
	
	var ue = UE.getEditor('editor');
 	ue.addListener('simpleupload_ready', function (types) {
        var btnUpload = document.getElementById('upload-cover');
        ue.fireEvent('simpleupload_custominit', btnUpload);
    });
    ue.addListener('simpleupload_customcomplete', function (types, id, link, title, alt) {
        document.getElementById('cover-img').src = link;
        document.getElementById('cover').value = link;//赋值表单的一个隐藏input
    });
});
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>